package cn.cjxy.userManageMent.controller;

import cn.cjxy.userManageMent.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //检测是否有用户信息
        HttpSession session = request.getSession();
        //获取用户信息
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser == null) {//没有登录的情况
            //返回登录页
            response.sendRedirect("/login.jsp");
            return false;
        }
        return true;
    }
}
